<?php
class Admin_Model_Presse extends Zend_Db_Table_Abstract
{
    protected $_name = 'presse';
	protected $_primary  = 'p_presse';
	protected $_idFieldName = 'p_presse';

	public function getListPresse()
	{
		$sql = $this->getAdapter()->select()
		->from($this->_name)
		->order('dtpubli desc');

		return $this->getAdapter()->fetchAll($sql);
	}

	public function getPresse($id)
	{
		$sql = $this->getAdapter()->select()
		->from($this->_name)
		->where('p_presse = ?', $id);

		return $this->getAdapter()->fetchRow($sql);
	}


	public function removePresse($id)
	{
		$this->getAdapter()->delete($this->_name, "p_presse =" . $id);
		return true;
	}

    public function getFichier($id)
	{
	    $sql = "SELECT fichier FROM ". $this->_name ." WHERE p_actu = $id";
	    return $this->getAdapter()->fetchRow($sql);
	}

    public function getVignette($id)
	{
	    $sql = "SELECT vignette FROM ". $this->_name ." WHERE p_actu = $id";
	    return $this->getAdapter()->fetchRow($sql);
	}

	public function save($data, $id = null)
	{
	    if ($id) {
	        $where = $this->getAdapter()->quoteInto($this->_idFieldName .' = ?', $id);
	        $this->getAdapter()->update($this->_name, $data, $where);
	    } else {
	        $this->getAdapter()->insert($this->_name, $data);
	    }
	    return true;
	}

}